// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	3/4/2014 10:29:22 PM				
// -----------------------------

#include "Color.h"

#include "Vector4.h"
#include "Vector3.h"

#include "CMath.h"

/* Constants */
const Color Color::White = Color(1.00f, 1.00f, 1.00f, 1.0f);
const Color Color::Black = Color(0.00f, 0.00f, 0.00f, 1.0f);
const Color Color::Grey = Color(0.50f, 0.50f, 0.50f, 1.0f);
const Color Color::Red = Color(1.00f, 0.00f, 0.00f, 1.0f);
const Color Color::Green = Color(0.00f, 1.00f, 0.00f, 1.0f);
const Color Color::Blue = Color(0.00f, 0.00f, 1.00f, 1.0f);
const Color Color::Cyan = Color(0.00f, 1.00f, 1.00f, 1.0f);
const Color Color::Yellow = Color(1.00f, 1.00f, 0.00f, 1.0f);
const Color Color::Magenta = Color(1.00f, 0.00f, 1.00f, 1.0f);
const Color Color::LightGrey = Color(0.75f, 0.75f, 0.75f, 1.0f);
const Color Color::LightRed = Color(1.00f, 0.25f, 0.25f, 1.0f);
const Color Color::LightGreen = Color(0.25f, 1.00f, 0.25f, 1.0f);
const Color Color::LightBlue = Color(0.25f, 0.25f, 1.00f, 1.0f);
const Color Color::LightCyan = Color(0.50f, 1.00f, 1.00f, 1.0f);
const Color Color::LightYellow = Color(1.00f, 1.00f, 0.50f, 1.0f);
const Color Color::LightMagenta = Color(1.00f, 0.50f, 1.00f, 1.0f);
const Color Color::DarkGrey = Color(0.25f, 0.25f, 0.25f, 1.0f);
const Color Color::DarkRed = Color(0.50f, 0.00f, 0.00f, 1.0f);
const Color Color::DarkGreen = Color(0.00f, 0.50f, 0.00f, 1.0f);
const Color Color::DarkBlue = Color(0.00f, 0.00f, 0.50f, 1.0f);
const Color Color::DarkCyan = Color(0.00f, 0.50f, 0.50f, 1.0f);
const Color Color::DarkYellow = Color(0.50f, 0.50f, 0.00f, 1.0f);
const Color Color::DarkMagenta = Color(0.50f, 0.00f, 0.50f, 1.0f);

/* Constructors */
Color::Color()
	: r(0.0f)
	, g(0.0f)
	, b(0.0f)
	, a(0.0f)
{

}
Color::Color(Float r, Float g, Float b)
	: r(r)
	, g(g)
	, b(b)
	, a(1.0f)
{

}
Color::Color(Float r, Float g, Float b, Float a)
	: r(r)
	, g(g)
	, b(b)
	, a(a)
{

}
Color::Color(UInt32 uColor)
	: r((1.0f / 255.0f) * ((uColor & 0xFF000000) >> 24))
	, g((1.0f / 255.0f) * ((uColor & 0x00FF0000) >> 16))
	, b((1.0f / 255.0f) * ((uColor & 0x0000FF00) >> 8))
	, a((1.0f / 255.0f) * ((uColor & 0x000000FF)))
{

}
Color::Color(Vector4 color)
	: r(color.x)
	, g(color.y)
	, b(color.z)
	, a(color.w)
{

}
Color::Color(Vector3 color)
	: r(color.x)
	, g(color.y)
	, b(color.z)
	, a(1.0f)
{

}
Color::Color(Vector3 color, Float a)
	: r(color.x)
	, g(color.y)
	, b(color.z)
	, a(a)
{

}

Color::Color(const Color& refColor)
	: r(refColor.r)
	, g(refColor.g)
	, b(refColor.b)
	, a(refColor.a)
{

}

Color& Color::operator=(const Color& refColor)
{
	r = refColor.r;
	g = refColor.g;
	b = refColor.b;
	a = refColor.a;
	return (*this);
}

Vector4 Color::ToVector4() const
{
	return Vector4(r, g, b, a);
}
Vector3 Color::ToVector3() const
{
	return Vector3(r, g, b);
}

Color Color::FromRGBA(UInt8 r, UInt8 g, UInt8 b, UInt8 a)
{
	Float d = 1.0f / 255.0f;
	Color clr;
	clr.r = r * d;
	clr.g = g * d;
	clr.b = b * d;
	clr.a = a * d;
	return clr;
}
Color Color::Lerp(const Color& a, const Color& b, Float alpha)
{
	Color clr;
	clr.r = Math::Lerp(a.r, b.r, alpha);
	clr.g = Math::Lerp(a.g, b.g, alpha);
	clr.b = Math::Lerp(a.b, b.b, alpha);
	clr.a = Math::Lerp(a.a, b.a, alpha);
	return clr;
}